/* 
 * File:   indexedList.h
 * Author: Mist
 *
 * Created on October 1, 2009, 5:20 PM
 */

#ifndef _INDEXEDLIST_H
#define	_INDEXEDLIST_H

#include "utility.h"
#include "string.h"

//The following class defines the linked list node
//This hold the links and the items it holds
//They are defined for both key as interger as well as character

class ListNode
{
public:
    //Define the construtures to be used to initialize the variables
    //As this works for both integer as well as character there will be
    //Hene there will be two construtors for interger as well as character
    //For the best functioning the system no to two nodes can have same index
    //Default constructors


    ListNode();
    //~ListNode();

    ListNode(void *itemPtr, int key);
    ListNode(void *itemPtr, char *key);

    //Index
    int noKey;          //Integer key
    char *nameKey;       //Name based key for index
    //Data to be held
    void *item;
    //link to next node
    ListNode *next;

};

// The following class defines a linked list structure
// This structure is used to store item (which are appended in the list)
// And Remove items based on the index
// The index for this case can be string or interger depending on the reference type

class IndexList
{
public:
    //Construtor that initialize the list
    IndexList();
    //~IndexList();

    // for both kinds of key
    void Append(void *itemPtr, int key);
    void Append(void *itemPtr, char *key);

    // This will remove the item based on index
    int Remove(int key);
    int Remove(char *key);

    // Following function will return the reference of the item only based on
    //index
    void *getReference(int key);
    void *getReference(char *key);


private:
    //Hold the pointers to start and end of the list.
    ListNode *head;
    ListNode *end;
};


#endif // INDEXEDLIST_H